#ifndef SINGLE_MEMBER_H
#define SINGLE_MEMBER_H

#include "asgka_common.h"
#include <Winsock.h>
#include <string>
#include <map>

class singleMember
{
public:
	singleMember();
	singleMember(const std::string &name, u_long net_addr);

	void setNetAddr(u_long net_addr);
	void setName(const std::string &name);
	void setSocket(SOCKET thesock);
	int setXigama(const std::string &groupname, c_asgka_element content);
	int setpubH(const std::string &groupname, c_asgka_element content);
	int setpubR(const std::string &groupname, c_asgka_element content);
	int setpubA(const std::string &groupname, c_asgka_element content);

	long getMemberID() const;
	char * FAR getMemberIP() const;
	u_long getNetAddr() const;
	SOCKET getSock() const;
	std::string getMemberName() const;
	asgka_element getMemberXigama(const std::string &groupname) const;
	asgka_element getMemberpubH(const std::string &groupname) const;
	asgka_element getMemberpubR(const std::string &groupname) const;
	asgka_element getMemberpubA(const std::string &groupname) const;

	bool isAlone() const;
	bool isXigamaOK(const std::string &groupname) const;
	bool isPubHOK(const std::string &groupname) const;
	bool isPubROK(const std::string &groupname) const;
	bool isPubAOK(const std::string &groupname) const;

	void joinedAGroup(const std::string &groupname);
	void leftAGroup(const std::string &groupname);

	~singleMember();

private:
	void addPairToMap(std::map<std::string, asgka_element> &themap, 
		const std::string &key, asgka_element value);
	void removeOneFromMap(std::map<std::string, asgka_element> &themap,
		const std::string &index);
	void removeAll(std::map<std::string, asgka_element> &themap);
	asgka_element getValueOfPair(const std::map<std::string, asgka_element> &themap,
		const std::string &index) const;
	bool isPairExist(const std::map<std::string, asgka_element> &themap,
		const std::string &index) const;

private:
	long m_id;

	std::string m_name;
	u_long m_net_addr;
	SOCKET m_socket;

	std::map<std::string, asgka_element> m_my_xigama;
	std::map<std::string, asgka_element> m_my_pubH;
	std::map<std::string, asgka_element> m_my_pubR;
	std::map<std::string, asgka_element> m_my_pubA;
};

#endif

